#include <p18f24k22.h>
#include "audio.h"

void audio_init()
{
	//Timer1 Initialize
	T1CONbits.TMR1ON = 1; 		// Starts timer1
	T1CONbits.T1CKPS0 = 1;		// Setting the predivide/prescale for timer1 to 1:8
	T1CONbits.T1CKPS1 = 1;		// Setting the predivide/prescale for timer1 to 1:8
	//Player Initialize
	TRISA &= ~0x30;
	LATA &= ~0x30;
}

void play_song(unsigned int song) {
	int i;
	int curr_song = 0;
	LATA &= ~0x30;
	for(i = 0; i < 8; i++)
	{
		while(!PIR1bits.TMR1IF);
		PIR1bits.TMR1IF = 0;
	}
	LATA |= 0x30;
	for(i = 0; i < 8; i++)
	{
		while(!PIR1bits.TMR1IF);
		PIR1bits.TMR1IF = 0;
	}
	while(curr_song++ != song)
	{
		LATA &= ~0x20;
		while(!PIR1bits.TMR1IF);
		PIR1bits.TMR1IF = 0;
		LATA |= 0x20;
		while(!PIR1bits.TMR1IF);
		PIR1bits.TMR1IF = 0;
	}
}
